// pages/user/pingjia.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: app.d.imageUrlFix,
    imageurls1: ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"],
    imageurls2: ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"],
    imageurls3: ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"],
    wuliu:"",
    kefu:"",
    goods:"",
    oga_shipping:0,
    oga_service:0,
    oga_goods:0,
    goods_id:0,
    goods_img:"",
    order_id:0,
    popErrorMsg: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
     this.setData({
         goods_id:parseInt(options.goods_id),
         order_id:parseInt(options.order_id),
         goods_img:options.goods_img,
         types: parseInt(options.types),
     });
  },
  submitApply: function (e) {
    var that = this;
    var formValue = e.detail.value;
    var oga_shipping = that.data.oga_shipping;
    var oga_service = that.data.oga_service;
    var oga_goods = that.data.oga_goods;
    var order_id = that.data.order_id;
    var goods_id = that.data.goods_id;
    var oga_text = formValue.oga_text;
    setTimeout(() => {
      if (oga_shipping == 0) {
        this.setData(
          { popErrorMsg: "物流星级不能为空" }
        );
        this.ohShitfadeOut();
        return;
      } else if (oga_service == 0) {
        this.setData(
          { popErrorMsg: "客服星级不能为空" }
        );
        this.ohShitfadeOut();
        return;
      } else if (oga_goods == 0) {
        this.setData(
          { popErrorMsg: "商品星级不能为空" }
        );
        this.ohShitfadeOut();
        return;
      } else if (oga_text == "" || oga_text==null){
        this.setData(
          { popErrorMsg: "评价内容不能为空" }
        );
      }else {
          that.apply(order_id, oga_shipping, oga_service, oga_goods, oga_text, goods_id);
      }
    }, 10)
  },

  apply(order_id, oga_shipping, oga_service, oga_goods, oga_text, goods_id) {
    var that = this;
    var pages = getCurrentPages();
    var prev = pages[pages.length - 2];//上个界面
    app.request("WxGoodsController", "addGoodsAppraise",
      {
        user_id: app.d.userId,
        order_id:order_id,
        oga_shipping: oga_shipping,
        oga_service: oga_service,
        oga_goods: oga_goods,
        oga_text: oga_text,
        goods_id: goods_id,
      }, function (data) {
        prev.setData({
          isRefresh: 1,
        })
        wx.navigateBack();
      });
  },
  ohShitfadeOut: function () {
    var fadeOutTimeout = setTimeout(() => {
      this.setData({ popErrorMsg: '' });
      clearTimeout(fadeOutTimeout);
    }, 3000);
  },
  /**
   * 物流星级
   */
  wuliulevel:function(e){
    var that = this;
    var imageurls = ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"];
    var type = e.currentTarget.dataset.type;
    for(let i=0;i<=type;i++){
      imageurls[i]="star_o.png";
    }
    if (type == 0) {
      that.setData({
        wuliu: "很差",
      });
    } else if (type == 1) {
      that.setData({
        wuliu: "差评",
      });
    } else if (type == 2) {
      that.setData({
        wuliu: "中评",
      });
    } else if (type == 3) {
      that.setData({
        wuliu: "好评",
      });
    } else {
      that.setData({
        wuliu: "很好",
      });
    }
    that.setData({
      imageurls1: imageurls,
      oga_shipping: type+1,
    });
  },
  // /**
  //  * 客服星级
  //  */
  kefulevel: function (e) {
    var that = this;
    var imageurls = ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"];
    var type = e.currentTarget.dataset.type;
    for (let i = 0; i <= type; i++) {
      imageurls[i] = "star_o.png";
    }
    if (type == 0) {
      that.setData({
        kefu: "很差",
      });
    } else if (type == 1) {
      that.setData({
        kefu: "差评",
      });
    } else if (type == 2) {
      that.setData({
        kefu: "中评",
      });
   }else if(type==3){
      that.setData({
        kefu: "好评",
      });
   }else {
      that.setData({
        kefu: "很好",
      });
    }
    that.setData({
      imageurls2: imageurls,
      oga_service:type+1,
    });
  },
  /**
   * 商品星级
   */
  goodslevel: function (e) {
    var that = this;
    var imageurls = ["star_line.png", "star_line.png", "star_line.png", "star_line.png", "star_line.png"];
    var type = e.currentTarget.dataset.type;
    for (let i = 0; i <= type; i++) {
      imageurls[i] = "star_o.png";
    }
    if (type == 0) {
      that.setData({
        goods: "很差",
      });
    } else if (type == 1) {
      that.setData({
        goods: "差评",
      });
    } else if (type == 2) {
      that.setData({
        goods: "中评",
      });
    } else if (type == 3) {
      that.setData({
        goods: "好评",
      });
    } else {
      that.setData({
        goods: "很好",
      });
    }
    that.setData({
      imageurls3: imageurls,
      oga_goods:type+1,
    });
  },

})